class Solution:
    def binaryTreePaths(self, root):
        """找出二叉树所有根到叶子的路径"""
        def backtrack(node, path, res):
            if not node:
                return
            path.append(str(node.val))
            if not node.left and not node.right:
                res.append("->".join(path))
            backtrack(node.left, path, res)
            backtrack(node.right, path, res)
            path.pop()
        
        res = []
        backtrack(root, [], res)
        return res